<template>
	<el-main class="bg edit_wrap">
		<el-form ref="form" :model="form" status-icon label-width="120px" v-if="is_view()">
		<el-row class="row_ce">
							<el-col v-if="$check_field('get','scenic_spot_name') || $check_field('add','scenic_spot_name') || $check_field('set','scenic_spot_name')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="景点名称" prop="scenic_spot_name">
												<el-input id="scenic_spot_name" v-model="form['scenic_spot_name']" placeholder="请输入景点名称"
							  v-if="(form['popular_attractions_id'] && $check_field('set','scenic_spot_name')) || (!form['popular_attractions_id'] && $check_field('add','scenic_spot_name'))" :disabled="disabledObj['scenic_spot_name_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','scenic_spot_name')">{{form['scenic_spot_name']}}</div>
											</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','types_of_tourist_attractions') || $check_field('add','types_of_tourist_attractions') || $check_field('set','types_of_tourist_attractions')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="景点类型" prop="types_of_tourist_attractions">
												<el-input id="types_of_tourist_attractions" v-model="form['types_of_tourist_attractions']" placeholder="请输入景点类型"
							  v-if="(form['popular_attractions_id'] && $check_field('set','types_of_tourist_attractions')) || (!form['popular_attractions_id'] && $check_field('add','types_of_tourist_attractions'))" :disabled="disabledObj['types_of_tourist_attractions_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','types_of_tourist_attractions')">{{form['types_of_tourist_attractions']}}</div>
											</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','location_of_tourist_attractions') || $check_field('add','location_of_tourist_attractions') || $check_field('set','location_of_tourist_attractions')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="景点位置" prop="location_of_tourist_attractions">
								<el-select id="location_of_tourist_attractions" v-model="form['location_of_tourist_attractions']"						v-if="(form['popular_attractions_id'] && $check_field('set','location_of_tourist_attractions')) || (!form['popular_attractions_id'] && $check_field('add','location_of_tourist_attractions'))">
						<el-option v-for="o in list_location_of_tourist_attractions" :key="o['region_name']" :label="o['region_name']"
							:value="o['region_name']">
						</el-option>
					</el-select>
					<div v-else-if="$check_field('get','location_of_tourist_attractions')">{{form['location_of_tourist_attractions']}}</div>
							</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','scenic_spot_ticket_prices') || $check_field('add','scenic_spot_ticket_prices') || $check_field('set','scenic_spot_ticket_prices')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="景点票价" prop="scenic_spot_ticket_prices">
								<el-input-number id="scenic_spot_ticket_prices" v-model.number="form['scenic_spot_ticket_prices']"
						v-if="(form['popular_attractions_id'] && $check_field('set','scenic_spot_ticket_prices')) || (!form['popular_attractions_id'] && $check_field('add','scenic_spot_ticket_prices'))" :disabled="disabledObj['scenic_spot_ticket_prices_isDisabled']"></el-input-number>
					<div v-else-if="$check_field('get','scenic_spot_ticket_prices')">{{form['scenic_spot_ticket_prices']}}</div>
							</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','opening_hours') || $check_field('add','opening_hours') || $check_field('set','opening_hours')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="开放时间" prop="opening_hours">
												<el-input id="opening_hours" v-model="form['opening_hours']" placeholder="请输入开放时间"
							  v-if="(form['popular_attractions_id'] && $check_field('set','opening_hours')) || (!form['popular_attractions_id'] && $check_field('add','opening_hours'))" :disabled="disabledObj['opening_hours_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','opening_hours')">{{form['opening_hours']}}</div>
											</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','scenic_spot_pictures') || $check_field('add','scenic_spot_pictures') || $check_field('set','scenic_spot_pictures')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="景点图片" prop="scenic_spot_pictures">
								<el-upload :disabled="disabledObj['scenic_spot_pictures_isDisabled']" class="avatar-uploader" drag
						accept="image/gif, image/jpeg, image/png, image/jpg" action="" :http-request="upload_scenic_spot_pictures"
						:show-file-list="false" v-if="(form['popular_attractions_id'] && $check_field('set','scenic_spot_pictures')) || (!form['popular_attractions_id'] && $check_field('add','scenic_spot_pictures'))">
						<img id="scenic_spot_pictures" v-if="form['scenic_spot_pictures']" :src="$fullUrl(form['scenic_spot_pictures'])" class="avatar">
						<i v-else class="el-icon-plus avatar-uploader-icon"></i>
					</el-upload>
					<el-image v-else-if="$check_field('get','scenic_spot_pictures')" style="width: 100px; height: 100px"
						:src="$fullUrl(form['scenic_spot_pictures'])" :preview-src-list="[$fullUrl(form['scenic_spot_pictures'])]">
						<div slot="error" class="image-slot">
							<img src="../../../public/img/error.png" style="width: 90px; height: 90px" />
						</div>
					</el-image>
							</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','introduction_to_scenic_spots') || $check_field('add','introduction_to_scenic_spots') || $check_field('set','introduction_to_scenic_spots')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="景点简介" prop="introduction_to_scenic_spots">
								<el-input type="textarea" id="introduction_to_scenic_spots" v-model="form['introduction_to_scenic_spots']" placeholder="请输入景点简介"
						v-if="(form['popular_attractions_id'] && $check_field('set','introduction_to_scenic_spots')) || (!form['popular_attractions_id'] && $check_field('add','introduction_to_scenic_spots'))" :disabled="disabledObj['introduction_to_scenic_spots_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','introduction_to_scenic_spots')">{{form['introduction_to_scenic_spots']}}</div>
							</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','route_planning') || $check_field('add','route_planning') || $check_field('set','route_planning')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="路线规划" prop="route_planning">
								<el-input type="textarea" id="route_planning" v-model="form['route_planning']" placeholder="请输入路线规划"
						v-if="(form['popular_attractions_id'] && $check_field('set','route_planning')) || (!form['popular_attractions_id'] && $check_field('add','route_planning'))" :disabled="disabledObj['route_planning_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','route_planning')">{{form['route_planning']}}</div>
							</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','tourist_attraction_guide') || $check_field('add','tourist_attraction_guide') || $check_field('set','tourist_attraction_guide')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="景点攻略" prop="tourist_attraction_guide">
								<el-input type="textarea" id="tourist_attraction_guide" v-model="form['tourist_attraction_guide']" placeholder="请输入景点攻略"
						v-if="(form['popular_attractions_id'] && $check_field('set','tourist_attraction_guide')) || (!form['popular_attractions_id'] && $check_field('add','tourist_attraction_guide'))" :disabled="disabledObj['tourist_attraction_guide_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','tourist_attraction_guide')">{{form['tourist_attraction_guide']}}</div>
							</el-form-item>
			</el-col>
						
	
	
		
		
	
	
	
	
	</el-row>
			<el-col :xs="24" :sm="12" :lg="8" class="el_form_btn_warp">
				<el-form-item v-if="$check_action('/popular_attractions/view','set') || $check_action('/popular_attractions/view','add') || $check_option('/popular_attractions/table','examine')">
					<el-button type="primary" @click="submit()">提交</el-button>
					<el-button @click="cancel()">取消</el-button>
				</el-form-item>
				<el-form-item v-else>
					<el-button @click="cancel()">返回</el-button>
				</el-form-item>
			</el-col>

		</el-form>
	</el-main>
</template>

<script>
	import mixin from "@/mixins/page.js";

	export default {
		mixins: [mixin],
		data() {
			return {
				field: "popular_attractions_id",
				url_add: "~/api/popular_attractions/add?",
				url_set: "~/api/popular_attractions/set?",
				url_get_obj: "~/api/popular_attractions/get_obj?",
				url_upload: "~/api/popular_attractions/upload?",

				query: {
					"popular_attractions_id": 0,
				},

				form: {
								"scenic_spot_name":  '', // 景点名称
										"types_of_tourist_attractions":  '', // 景点类型
										"location_of_tourist_attractions":  '', // 景点位置
										"scenic_spot_ticket_prices":  0, // 景点票价
										"opening_hours":  '', // 开放时间
										"scenic_spot_pictures":  '', // 景点图片
										"introduction_to_scenic_spots":  '', // 景点简介
										"route_planning":  '', // 路线规划
										"tourist_attraction_guide":  '', // 景点攻略
											"popular_attractions_id": 0, // ID
													},
				disabledObj:{
								"scenic_spot_name_isDisabled": false,
										"types_of_tourist_attractions_isDisabled": false,
										"location_of_tourist_attractions_isDisabled": false,
					          			"scenic_spot_ticket_prices_isDisabled": false,
										"opening_hours_isDisabled": false,
										"scenic_spot_pictures_isDisabled": false,
										"introduction_to_scenic_spots_isDisabled": false,
										"route_planning_isDisabled": false,
										"tourist_attraction_guide_isDisabled": false,
										},

	
				
										// 景点位置选项列表
				list_location_of_tourist_attractions: [""],
	
				
				
				
				
				
				
			
			}
		},
		methods: {

	
	
			
	
			
				/**
			 * 获取景点位置列表
			 */
			async get_list_location_of_tourist_attractions() {
				var json = await this.$get("~/api/region_name/get_list?");
				if(json.result && json.result.list){
					this.list_location_of_tourist_attractions = json.result.list;
				}
				else if(json.error){
					console.error(json.error);
				}
			},
					
			
	
			
	
						/**
			 * 上传景点图片
			 * @param {Object} param 图片参数
			 */
			upload_scenic_spot_pictures(param){
									this.uploadFile(param.file, "scenic_spot_pictures");
								},
	
	
			
	
			
	
			
	
		
			/**
			 * 获取对象之前
			 * @param {Object} param
			 */
			get_obj_before(param) {
				var form = "";
																																	if(this.form && form){
					Object.keys(this.form).forEach(key => {
						Object.keys(form).forEach(dbKey => {
							// if(dbKey === "charging_standard"){
							// 	this.form['charging_rules'] = form[dbKey];
							// 	this.disabledObj['charging_rules_isDisabled'] = true;
							// };
							if(key === dbKey){
								this.disabledObj[key+'_isDisabled'] = true;
								this.form[key] = form[dbKey]
							}
							if(dbKey === "source_table"){
								this.form['source_table'] = form[dbKey];
							}
							if(dbKey === "source_id"){
								this.form['source_id'] = form[dbKey];
							}
							if(dbKey === "source_user_id"){
								this.form['source_user_id'] = form[dbKey];
							}
						})
					})
				}
																						$.db.del("form");
				return param;
			},

			/**
			 * 获取对象之后
			 * @param {Object} json
			 * @param {Object} func
			 */
			get_obj_after(json, func){

																																													

			},

																																																																					async submit(param, func){
				if (!param) {
					param = this.form;
				}
								var pm = this.events("submit_before", Object.assign({}, param)) || param;
				var msg = await this.events("submit_check", pm);
				var ret;
				if (msg) {
					this.$toast(msg, 'danger');
				} else {
																																																																							ret = this.events("submit_main", pm, func);
				}
				return ret;
			},
			/**
			 * 提交前验证事件
			 * @param {Object} 请求参数
			 * @return {String} 验证成功返回null, 失败返回错误提示
			 */
						submit_check(param) {
																																																																																																													return null;
			},

			is_view(){
				// var bl = this.user_group == "管理员";
				var bl = false;

				if(!bl){
					bl = this.$check_action('/popular_attractions/table','add');
					console.log(bl ? "你有表格添加权限视作有添加权限" : "你没有表格添加权限");
				}
				if(!bl){
					bl = this.$check_action('/popular_attractions/table','set');
					console.log(bl ? "你有表格添加权限视作有修改权限" : "你没有表格修改权限");
				}
				if(!bl){
					bl = this.$check_action('/popular_attractions/view','add');
					console.log(bl ? "你有视图添加权限视作有添加权限" : "你没有视图添加权限");
				}
				if(!bl){
					bl = this.$check_action('/popular_attractions/view','set');
					console.log(bl ? "你有视图修改权限视作有修改权限" : "你没有视图修改权限");
				}
				if(!bl){
					bl = this.$check_action('/popular_attractions/view','get');
					console.log(bl ? "你有视图查询权限视作有查询权限" : "你没有视图查询权限");
				}

				console.log(bl ? "具有当前页面的查看权，请注意这不代表你有字段的查看权" : "无权查看当前页，请注意即便有字段查询权限没有页面查询权限也不行");

				return bl;
			},
			/**
			 * 上传文件
			 * @param {Object} param
			 */
			uploadimg(param) {
				this.uploadFile(param.file, "avatar");
			},

		},
		created() {
								this.get_list_location_of_tourist_attractions();
																},
	}
</script>

<style>
	.avatar-uploader .el-upload {
		border: 1px dashed #d9d9d9;
		border-radius: 6px;
		cursor: pointer;
		position: relative;
		overflow: hidden;
	}

	.avatar-uploader .el-upload:hover {
		border-color: #409EFF;
	}

	.avatar-uploader-icon {
		font-size: 28px;
		color: #8c939d;
		width: 178px;
		height: 178px;
		line-height: 178px;
		text-align: center;
	}

	.avatar {
		width: 178px;
		height: 178px;
		display: block;
	}
	
	.img_multiple{
		overflow: hidden;
	}
	.img_multiple .img_block{
		float: left;
		margin-right: 5px;
		margin-bottom: 5px;
		position: relative;
	}
	.img_multiple .img_block img{
		height: 100px;
		width: auto;
	}
	.img_multiple .img_del{
		position: absolute;
		top: 5px;
		right: 5px;
		width: 20px;
		height: 20px;
		background: #0000008a;
		color: #fff;
		line-height: 20px;
		text-align: center;
		border-radius: 100%;
		cursor: pointer;
	}




</style>
